home *** CD-ROM | disk | FTP | other *** search
/ El Mac 1 / Magazine.iso / EL MAC 1 / Shareware / HyperCard / XCMD Docs / CompileIt! Source Code / GetAppIcon(fileName) < prev    next >
Encoding:
Text File  |  1995-08-20  |  2.1 KB  |  84 lines  |  [TEXT/ttxt]

  1. global ICN_ID:I,GotIt:B
  2.  
  3. function GetAppIcon fileName
  4.   put CurResFile() into oldFile
  5.   put OpenResFile(filename) into refNum
  6.   UseResFile refNum
  7.   put 1 into resHndl
  8.   put 1 into x
  9.   repeat until resHndl=0
  10.     put Get1IndResource("FREF",x) into resHndl
  11.     if resHndl≠nil then
  12.       if resHndl@@.osType="APPL" then
  13.         put resHndl@@.integerType[3] into ICN_ID_2
  14.         put true into GotIt
  15.         releaseResource resHndl
  16.         exit repeat
  17.       end if
  18.       releaseResource resHndl
  19.     end if
  20.     add one to x
  21.   end repeat
  22.   if GotIt then
  23.     DoTheBNDL ICN_ID_2
  24.     if gotit then
  25.       get ICN_2_ICON(ICN_ID,oldFile)
  26.     else get "application"
  27.   else get "application"
  28.   UseResFile oldFile
  29.   CloseResFile refNum
  30.   return it
  31. end GetAppIcon
  32.  
  33. -- my library code
  34.  
  35. function ICN_2_ICON resId,oldResFile
  36.   put GetResource("ICN#",resId) into hndl
  37.   if hndl=NIL then return "application" -- Δ
  38.   else
  39.     put NewHandleClear(128) into iconH
  40.     BlockMove hndl@,iconH@,128
  41.     releaseResource hndl
  42.     UseResFile oldResFile -- Δ
  43.     get uniqueId("ICON") -- Δ
  44.     AddResource iconH,"ICON",it,("An Application's Icon--id" && it)
  45.     WriteResource iconH -- Δ
  46.     releaseResource iconH
  47.     updateResFile curResFile() -- ΔΔΔ
  48.     return it
  49.   end if
  50. end ICN_2_ICON
  51.  
  52. on DoTheBNDL LocalID
  53.   put Get1IndResource("BNDL",1) into bHand
  54.   put ReadBNDL(bHand,LocalID,"ICN#") into ICN_ID
  55.   releaseResource bHand
  56. end DoTheBNDL
  57.  
  58. function ReadBNDL bHand,LocalID,BNDL_TYPE
  59.   put false into GotIt
  60.   MoveHHi bHand
  61.   Hlock bHand
  62.   put bHand@.ptrType into ptr
  63.   add 6 to ptr -- creator & owner id
  64.   put (ptr@.integerType)+1 into MainCount
  65.   add 2 to ptr -- main list count
  66.   repeat mainCount
  67.     if ptr@.osType≠BNDL_TYPE then
  68.       add 4 to ptr -- type
  69.       add (ptr@.integerType*4)+6 to ptr
  70.     else
  71.       add 4 to ptr -- type
  72.       put (ptr@.integerType)+1 into subCount
  73.       add 2 to ptr -- sub count
  74.       repeat subcount
  75.         if ptr@.integerType=LocalID then
  76.           put ptr@.integerType[2] into resID
  77.           put true into GotIt
  78.           return resID
  79.         else add 4 to ptr
  80.       end repeat
  81.     end if
  82.   end repeat
  83.   return 0
  84. end ReadBNDL